package com.tancire.web.controller.company;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.net.domain.CrmCompanyPurse;
import com.tancire.net.service.ICrmCompanyPurseService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 客户收益Controller
 *
 * @author chenchao
 * @date 2023-12-30
 */
@RestController
@RequestMapping("/net/crmCompanyPurse")
public class CrmCompanyPurseController extends BaseController {
    @Resource
    private ICrmCompanyPurseService crmCompanyPurseService;

    /**
     * 查询客户收益列表
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyPurse:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCompanyPurse crmCompanyPurse) {
        startPage();
        List<CrmCompanyPurse> list = crmCompanyPurseService.selectCrmCompanyPurseList(crmCompanyPurse);
        return getDataTable(list);
    }

    /**
     * 导出客户收益列表
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyPurse:export')")
    @Log(title = "客户收益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCompanyPurse crmCompanyPurse) {
        List<CrmCompanyPurse> list = crmCompanyPurseService.selectCrmCompanyPurseList(crmCompanyPurse);
        ExcelUtil<CrmCompanyPurse> util = new ExcelUtil<CrmCompanyPurse>(CrmCompanyPurse.class);
        util.exportExcel(response, list, "客户收益数据");
    }

    /**
     * 获取客户收益详细信息
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyPurse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(crmCompanyPurseService.selectCrmCompanyPurseById(id));
    }

    /**
     * 新增客户收益
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyPurse:add')")
    @Log(title = "客户收益", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCompanyPurse crmCompanyPurse) {
        return toAjax(crmCompanyPurseService.insertCrmCompanyPurse(crmCompanyPurse));
    }

    /**
     * 修改客户收益
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyPurse:edit')")
    @Log(title = "客户收益", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCompanyPurse crmCompanyPurse) {
        return toAjax(crmCompanyPurseService.updateCrmCompanyPurse(crmCompanyPurse));
    }

    /**
     * 删除客户收益
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyPurse:remove')")
    @Log(title = "客户收益", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmCompanyPurseService.deleteCrmCompanyPurseByIds(ids));
    }
}
